/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.weed.client.component.ext;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JComponent;
import javax.swing.JFrame;

/**
 *
 * @author Jason
 */
public class RLayer extends javax.swing.JLayeredPane {
    JComponent component;
    public RLayer(JComponent component){
        this.component = component;
        JFrame frame = getFrame(component);
        Point p = component.getLocation();
        this.setBounds(p.x,p.y,component.getWidth(), component.getHeight());
        //this.setOpaque(true);
        frame.setLayeredPane(this);
    }
    private static JFrame getFrame(Component c) {
        Component w = c;
        while(!(w instanceof JFrame) && (w!=null)) {
            w = w.getParent();
        }
        return (JFrame)w;
    }
    protected void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        Rectangle clip = g.getClipBounds();
        g2.setColor(new Color(0.123f, 0.123f, 0.123f,0.5f));
        g2.fillRect(clip.x, clip.y, clip.width, clip.height);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.9f));
        g2.setColor(this.getBackground());
       super.paintComponent(g);
    }

}
